home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d3
/
rettig.arc
/
TRSOURCE.EXE
/
DEPDB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-22
|
1KB
|
51 lines
/*********
*
* DEPDB.C
*
* by Ralph Davis
* modified by Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
*********/
/* DEPDB : Depreciation by declining-balance method
Computes depreciation calculated as percent
of current value.
SYNTAX: DEPDB(value, rate, periods)
where value = current value
rate = depreciation rate per period
periods = number of periods in calculations
RETURNS: depreciation over specified period of time.
*/
#include "trlib.h"
TRTYPE depdb()
{
if ( PCOUNT==3 && ISNUM(1) && ISNUM(2) && ISNUM(3) )
{
double value = _parnd(1);
double rate = _parnd(2);
int periods = (int)_parnd(3);
double depr = 0;
int i;
for (i = 0; i < periods; i++)
{
depr += value * rate; /* Depreciation = value times
rate of depreciation */
value *= (1.0 - rate); /* New value = old value reduced
by rate of depreciation */
}
_retnd(depr);
}
else
_retnd( (double)ERROR );
}